<?php

/**
 * DetFactCompra form.
 *
 * @package    odontopc
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class DetFactCompraForm extends BaseDetFactCompraForm
{
  public function configure()
  {
    parent::configure();
    $this->widgetSchema['factcompra_id'] = new sfWidgetFormInputHidden();
    
    $q = Doctrine_Query::create()
      ->from('Grupoprod g')
      ->leftJoin('g.Productos p')
      ->where('grupoprod_id = 15')
      ->orderBy('g.nombre')
      ->addOrderBy('p.orden_grupo')
      ->addOrderBy('p.nombre');
     
    $res = $q->fetchArray();
    
    $choices = array("" => "");
    
    foreach($res as $grupos){
      $prods = array();
      foreach($grupos['Productos'] as $prod){
        $prods[$prod['id']] = $prod['nombre'];  
      }
      $choices[$grupos['nombre']] = $prods; 
    }
    
    $this->widgetSchema['producto_id'] = new sfWidgetFormChoice(array('choices' => $choices), array('data-placeholder' => 'Escriba un Nombre...', 'class' => 'chzn-select', 'style' => 'width:450px;'));    
  }
}
